const { defineConfig } = require('@vue/cli-service')
const Mock =require('mockjs')
const bodyParser=require('body-parser')
const data=Mock.mock({
  "img|4":[
   '@image(100x100,@color)'
  ],
  "list|9":[{
    title:"@ctitle(4)",
    "children|4":[{
      id:'@id',
      img:'@image(100x100,@color)',
      word:"@cword(4)",
    }]
  }],
  
})
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave:false,
  devServer: {
    onAfterSetupMiddleware: function ({app}) {
      app.get('/swiper',(req,res)=>{
        res.send(data.img)
      })
      app.get('/classify/list',(req,res)=>{
        res.send(data.list)
      })
      //登录
      app.use(bodyParser.json())
      app.get('/login',(req,res)=>{
        const {phone,password} =req.query
        if(phone==="123456" && password==='qwer'){
          res.send({
            code:200,
            msg:'登陆成功'
          })
        }else{
          res.send({
            code:404,
            msg:'登陆失败'
          })
        }
      })
      //详情
      // app.get('/detail/list',(req,res)=>{
      //   const {id,index} =req.query
      // let newData=data.list[index].children.filter((item,index)=>{
      //   return item.id ===id
      // })
      //   console.log(newData[0]);
      //   res.send(newData[0])
      // })
      app.get('/tj',(req,res)=>{   //推荐
        const datalist=Mock.mock({
          "title|50":[{
            img:'@image(100x100,@color)',
            title:"@ctitle(5)",
          }]
        })
        res.send(datalist.title)
    })

    },
  },
})
